package leetcode.code0052;

public class Solution extends Solution52 {

	private int range;
	private int ans;

	@Override
	public int totalNQueens(int n) {
		ans = 0;
		range = (1 << n) - 1;
		totalNQueens(0, 0, 0);
		return ans;
	}

	public void totalNQueens(int col, int left, int right) {
		if (range == col)
			ans++;
		int avl = range & (~(col | left | right));
		while (avl > 0) {
			int q = avl & -avl;
			avl &= avl - 1;
//			avl -= q;
//			int q = avl & (~avl + 1);
			totalNQueens(col | q, (left | q) << 1, (right | q) >>> 1);
		}
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
//		so.totalNQueens(4);
		int n = 178;
		System.out.println(Integer.toBinaryString(-n));
		System.out.println(Integer.toBinaryString(~n + 1));
		System.out.println(Integer.toBinaryString(n & -n));
		System.out.println(Integer.toBinaryString(n & (~n + 1)));
	}

}
